/*
==========
Fixture.c - Contains implementation of Fixture class
==========
*/
#include <cassert>
#include "Fixture.h"

static const std::string ErrUncaughtExceptionMsg = "An uncaught exception occurred.";

void Fixture::AddTest ( Test* tst )
{
	assert(!!tst);
	if(tst)
	{
		m_tests.push_back(tst);
	}
}
TestResult Fixture::RunTest ( int idx )
{
	assert(idx>=0);
	assert(idx < m_tests.size());
	try {
		return m_tests.at(idx)->operator()(*this);
	}
	catch( ... )
	{
		return TestResult ( m_tests.at(idx)->GetName(), false, ErrUncaughtExceptionMsg );
	}
}
std::vector<TestResult> Fixture::RunAllTests (  )
{
	std::vector<TestResult> results;
	for( TestList_t::iterator beg = m_tests.begin(), end = m_tests.end(); beg!=end; std::advance(beg, 1) ) {
		try {
			results.push_back( (*beg)->operator()(*this) );
		}
		catch( ... )
		{
			results.push_back( TestResult((*beg)->GetName(), false, ErrUncaughtExceptionMsg) );
		}
	}
	return results;
}
int Fixture::GetNbTests ( ) const
{
	return m_tests.size();
}